/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.meuevento.util;

import com.meuevento.business.event.Event;
import com.meuevento.business.event.EventService;
import com.meuevento.business.user.User;
import com.meuevento.business.user.UserService;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author jfrs
 */
@Stateless
public class Populator {

     @EJB UserService userService;
     @EJB EventService eventService;


    public void populate(){
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(new Date());
        if(userService.listUsers().size() == 0){
            User rmpestano = userService.insertUser(new User( "rmpestano", "rmpestano", "rmpestano@yahoo.com.br", null));
            Event rmpestanoEvent = eventService.insert(new Event("rmpestano event ", "rmpestano place ",gc));
            userService.addEvent(rmpestanoEvent, rmpestano);
            //rmpestanoEvent.getUser().add(rmpestano);

            Event vcallegaroEvent = eventService.insert(new Event("vcallegaro event ", "vcallegaro place ",gc));
            ArrayList<Event> vcallegaroEvents = new ArrayList<Event>();
            vcallegaroEvents.add(vcallegaroEvent);
            userService.insertUser(new User( "vcallegaro", "vcallegaro", "vcallegaro@gmail.com", vcallegaroEvents));

            userService.insertUser(new User( "aklinger", "aklinger", "aklinger@hotmail.com", null));
            userService.insertUser(new User( "fvarella", "fvarella", "fvarella@inf.ufrgs.br", null));
            userService.insertUser(new User( "admin", "admin", "admin@meuevento.com.br", null));
        }
        
        User u = userService.findByNameAndPass("rmpestano", "rmpestano");

           u.getEvents();

//        for (Event event :  userService.findByNameAndPass("rmpestano", "rmpestano").getEvents()) {
//            System.out.println(event.getEventId() +" " + event.getName()); // tá populando mas relacionamento 'event_users' não
//        }

       // Event e = eventService.findByName("rmpestano event");


    }



}

